﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace TestBrownser
{
    public partial class FrmItemSelect<T> : Form where T : class
    {
        public string Caption
        {
            get
            {
                return this.Caption;
            }
            set
            {
                this.Caption = value;
            }
        }

        public string Summray
        {
            get
            {
                return lblSummary.Text;
            }
            set
            {
                lblSummary.Text = value;
            }
        }

        public T SelectedItem
        {
            get
            { return lbData.SelectedItem as T; }
            set
            {
                lbData.SelectedItem = value; ;
            }
        }

        public string DisplayField
        {
            set
            {
                lbData.DisplayMember = value;
            }

            protected get
            {
                return lbData.DisplayMember;
            }
        }

        private List<T> dataSource = null;
        public List<T> DataSource
        {
            set
            {
                this.dataSource = value;
                lbData.DataSource = value;
            }
            get
            {
                return dataSource;
            }
        }

        public FrmItemSelect()
        {
            InitializeComponent();
        }

        public FrmItemSelect(List<T> dataSource)
            : this()
        {
            this.DataSource = dataSource;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
        }

        private void lbData_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
        }
    }
}
